<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<!DOCTYPE>
<html>
	<head>
		<title>提现</title>
		<script src="${basePath}resources/js/Jquery-md5.js"></script>
		
	</head>
	<body>
		<div class="loading"></div>
		<!-- header -->
		<header>
			<a href="javascript:history.go(-1);" class="top_fh">余额</a>
		</header>
		<!-- header end -->
		
		<div class="page nb_page my_yuepage">
			<div class="my_yueinner">
				<ul>
					<li>
						<span>提现方式</span>
						<em>微信</em>
					</li>
					<li>
						<div class="my_yuetx">
							<span>金额</span>
							<p><i></i><input id="totalMoney"type="text" placeholder="提现金额"></p>
							<p><u>余额￥${balances.currentmoney/100}</u></p>
						</div>
					</li>
					<!--  <li>
						<span>手续费</span>
						<i id="smoney">￥0.0</i>
						<b>微信收取千分之六手续费</b>
					</li>
					<li>
						<span>实际到账</span>
						<i id="gmoney">￥0.0</i>
					</li>-->  
				</ul>
				<div class="my_txbutton"><a href="JavaScript:;" class='cur'>提现</a></div>
			</div>
		</div>

		<!-- 余额提现 -->
		<div class="home_zftcpop ty_pop">
			<div class="popbg"></div>
			<div class="zftc_inner">
				<em>请输入提现密码</em>
				<p>余额提现</p>
				<p><span id="balance">￥100.00</span></p>
				<div class="zfform">
					<form action="" method="post" name="payPassword" id="form_paypsw">
						<div id="payPassword_container" class="alieditContainer clearfix" data-busy="0">
							<div class="i-block" data-error="i_error">
								<div class="i-block six-password">
									<input class="i-text sixDigitPassword" id="payPassword_rsainput" type="password" autocomplete="off" required="required" value="" name="payPassword_rsainput" data-role="sixDigitPassword" tabindex="" maxlength="6" minlength="6" aria-required="true">
									<div tabindex="0" class="sixDigitPassword-box">
										<i style="border-color: transparent;" class=""><b></b></i>
										<i><b></b></i>
										<i><b></b></i>
										<i><b></b></i>
										<i><b></b></i>
										<i><b></b></i>
										<span id="cardwrap" data-role="cardwrap"></span>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<!-- 余额提现 end -->
	</body>
</html>
<script src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>

<script>
$(function(){
	//控制金额为数字
	var regwords=/^\d+\.?\d{0,2}$/;
	var regword=/^\d/;
	$("#totalMoney").on("keyup", function(){     /*键盘弹起*/
		//var words=(parseFloat($(this).val())).toFixed(2);
		var words=$(this).val();
		if(regwords.test(words)){
			$(this).val(words);
		}else if(regword.test(words)){
			words=(parseFloat($(this).val())).toFixed(2);
			$(this).val(words);
		}else{
			$(this).val("");
		}
	})

	//验证输入金额
	$(".my_yuetx p input").blur(function(){
			
			if($(this).val()>${balances.currentmoney/100}){
				alert('余额不足!');
				return ;
			}
			if($(".my_yuetx p input").val()==null||$(".my_yuetx p input").val()<=0){
				alert('请输入提现金额');

			}
			$('#balance').text('￥'+$(this).val());
			
			
		/* 	var smoney=$(this).val()*0.0006;
			var money=Math.floor(smoney * 100) / 100  ;
			if(smoney>money){
					money=money+0.01;
			}
			$('#smoney').text(money)
			$('#gmoney').text($(this).val()-money) */
			
			//giveMoney('123456',$(this).val());

	});
	
	// 输入支付密码
	var _formPay = $('#form_paypsw');
	var payPassword = $("#payPassword_container"),
    _this = payPassword.find('i'),	
	k=0,j=0,
	password = '' ,
	_cardwrap = $('#cardwrap');
	//点击隐藏的input密码框,在6个显示的密码框的第一个框显示光标
	payPassword.on('focus',"input[name='payPassword_rsainput']",function(){
	
		var _this = payPassword.find('i');
		if(payPassword.attr('data-busy') === '0'){ 
		//在第一个密码框中添加光标样式

		   _this.eq(k).addClass("active");
		   _cardwrap.css('visibility','visible');
		   payPassword.attr('data-busy','1');
		}
		
	});	
	
	
	//change时去除输入框的高亮，用户再次输入密码时需再次点击
	payPassword.on('change',"input[name='payPassword_rsainput']",function(){
		_cardwrap.css('visibility','hidden');
		_this.eq(k).removeClass("active");
		payPassword.attr('data-busy','0');
	}).on('blur',"input[name='payPassword_rsainput']",function(){
		
		_cardwrap.css('visibility','hidden');
		_this.eq(k).removeClass("active");					
		payPassword.attr('data-busy','0');
		
	});
	//使用keyup事件，绑定键盘上的数字按键和backspace按键
	payPassword.on('keyup',"input[name='payPassword_rsainput']",function(e){
	
	var  e = (e) ? e : window.event;
	
	//键盘上的数字键按下才可以输入
	if(e.keyCode == 8 || (e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)){
			k = this.value.length;//输入框里面的密码长度
			l = _this.size();//6
			
			for(;l--;){
			//输入到第几个密码框，第几个密码框就显示高亮和光标（在输入框内有2个数字密码，第三个密码框要显示高亮和光标，之前的显示黑点后面的显示空白，输入和删除都一样）
				if(l === k){
					_this.eq(l).addClass("active");
					_this.eq(l).find('b').css('visibility','hidden');
					
				}else{
					_this.eq(l).removeClass("active");
					_this.eq(l).find('b').css('visibility', l < k ? 'visible' : 'hidden');
				}
			if(k === 6){
				$(".ty_pop").hide();
				giveMoney($(".sixDigitPassword").val(),$('#totalMoney').val());;;;
				j = 5;
				//输入完密码执行
				//console.log($(".sixDigitPassword").val())
				//console.log("日志：金钱数："+$('#totalMoney').val())
				//	$("#home_zftcpop ty_pop").hidden();
				//giveMoney($(".sixDigitPassword").val(),$('#totalMoney').val())
				return;
				
			}else{
				j = k;
			}
			$('#cardwrap').css('left',j*16.6+'%');
		
			}
		}else{
		//输入其他字符，直接清空
			var _val = this.value;
			this.value = _val.replace(/\D/g,'');
		}
	});	
	
});

function  giveMoney( password, totalmey)
{
	//alert(createPassword(password,password));
	if($(".my_yuetx p input").val()>${balances.currentmoney/100}){
		alert('余额不足!');
		return ;
	}
	if($(".my_yuetx p input").val()==null||$(".my_yuetx p input").val()<=0){
		alert('请输入提现金额');
		return 
	}
	$.ajax({
		url:'${basePath}wechat/income/cash/lost',
		type : 'POST',
		data : {
				'password':createPassword(password,password),
				'totalmoney':totalmey*100
		},					
		error: function (response) {
			ViewHelper.func.ajaxWechatErrorMessage(response);
		},
		success: function (ret) {
			alert(ret.info);
		}
	}); 
	
}
</script>

